<?php

namespace App\Admin\Controllers;

use App\Models\PointGoods;
use App\Models\PointGoodsOrder;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;
use Illuminate\Support\Arr;

class PointGoodsOrderController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '积分商品订单';
    protected $goodsStatus = [
        'on'  => ['value' => 1, 'text' => '正常', 'color' => 'success'],
        'off' => ['value' => 2, 'text' => '已取消', 'color' => 'danger'],
    ];
    protected $status = [
    	1 => '正常',
	    2 => '已取消',
    ];

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new PointGoodsOrder());
	
        $grid->column('store.detail', '申请兑换门店名称')->display(function ($item) {
        	return Arr::get($item, 'name', '未知');
        });
        $grid->column('order_no', '订单号');
        $grid->column('name', '兑换人姓名');
        $grid->column('mobile', __('Mobile'));
        $grid->column('pointGoods.name', '积分商品名称');
        $grid->column('number', '数量');
        $grid->column('status', __('Status'))->switch($this->goodsStatus);
        //$grid->column('remark', __('Remark'));
        $grid->column('created_at', __('Created at'));
		
        $grid->disableCreateButton();
        $grid->filter(function ($filter) {
        	$filter->disableIdFilter();
        	$filter->like('name', __('Name'));
        	$filter->like('mobile', __('Mobile'));
        });
        
        $grid->actions(function (Grid\Displayers\Actions $actions) {
            $actions->disableView();
            $actions->disableEdit(false);
        });
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(PointGoodsOrder::findOrFail($id));

        //$show->field('id', __('Id'));
        $show->field('name', '兑换人名称');
        $show->field('mobile', __('Mobile'));
        $show->field('order_no', '订单号');
        $show->field('pointGoods.name', '积分商品名称');
        $show->field('number', '数量');
        $show->field('remark', __('Remark'));
        $show->field('status', __('Status'))->using($this->status);
        $show->field('created_at', __('Created at'));
        
        $show->panel()
		    ->tools(function ($tools) {
		        //$tools->disableEdit();
		    });;
        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new PointGoodsOrder());

        $form->text('name', '兑换人');
        $form->text('mobile', __('Mobile'));
        $form->text('order_no', '订单号')->disable();
        //$form->select('point_goods_id', '积分商品名称')->options(PointGoods::all()->pluck('name', 'id'))->disable();
        $form->text('goods.name', '积分商品名称')->disable();
        $form->number('number', '数量')->disable();
        $form->textarea('remark', __('Remark'))->disable();
        $form->switch('status', __('Status'))->states([
        	'on'  => ['value' => 1, 'text' => '正常', 'color' => 'success'],
            'off' => ['value' => 2, 'text' => '已取消', 'color' => 'danger'],
        ]);
		
        $form->disableReset();
        $form->footer(function (Form\Footer $footer) {
        	//$footer->disableSubmit();
        	$footer->disableCreatingCheck();
        	$footer->disableEditingCheck();
        });
        
        return $form;
    }
}
